package org.xlp.mvc.definition;

import org.xlp.assertion.AssertUtils;
import org.xlp.bean.base.IBeanDefinition;
import org.xlp.bean.base.IBeanDefinitionCreator;
import org.xlp.mvc.annotation.Controller;

/**
 * {@link org.xlp.mvc.annotation.Controller}注解标识的类bean定义创建器
 */
public class ControllerAnnotationBeanDefinitionCreator implements IBeanDefinitionCreator {
    /**
     * 根据给定的bean创建对应的bean定义
     *
     * @param beanClass bean类型
     * @return
     * @throws NullPointerException 假如参数为null，则抛出该异常
     */
    @Override
    public IBeanDefinition createBeanDefinition(Class<?> beanClass) {
        AssertUtils.isNotNull(beanClass, "beanClass parameter must not be null!");
        if (beanClass.getAnnotation(Controller.class) != null)
            return new ControllerAnnotationBeanDefinition(beanClass);

        return new CBControllerAnnotationBeanDefinition(beanClass);
    }
}
